#coding:utf-8
import json
import os
import sys
from django.http import HttpResponse
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
sys.path.append('/home/cheungssh/mysite')
sys.path.append('/home/cheungssh/mysite/mysite/cheungssh')
def login_check(func):
	def login_auth_check(request,*args,**kws):
		info={}
		if request.method=='POST':
			request_content=request.POST
		else:
			request_content=request.GET
		callback=request.GET.get('callback')
		isAuth=False
		if request.user.is_authenticated():
			info["username"]=request.user.username
			isAuth=True
		if isAuth:
			return func(request,*args,**kws)
		else:
			backinfo={'status':'login'}
			backinfo=json.dumps(backinfo,encoding="utf8",ensure_ascii=False)
			if callback:
				info="%s(%s)"  % (callback,backinfo)
			else:
				info="%s"  % (backinfo)
			return HttpResponse(info)
	return login_auth_check
